<!--环境信息年报 RptAnnual-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120" style="margin-top: 10px">
            <Row v-show="!switchFlag" class="query-form" >
                <Col span="8">
                    <FormItem label="企业名称：" prop="order">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyId' :orgTree="true"
                                      :currentOrgId="dataToQuery.companyId" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label='年度：' prop='year'>
                        <DatePicker class="query-form-el" :clearable="false" placeholder="请选择年度" v-model='dataToQuery.yearDate' type="year"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button type="primary" class="ivu-btn-query" icon="md-search"  @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight" :row-class-name="rowClassName" no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading'
               border :columns="columns1"  :data="dataTable" >
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    import orgFieldOptions from './orgFieldOptions'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    export default {
        name: "rptAnnual",
        components:{
            cascaderDom
        },
        data(){
            return {
                ...this.createCommonDataField(),
                // 列表
                columns1: [
                    { title: '序号', width: 80, fixed: 'left', align: 'center', render: (h, params) => {
                        if(params.index == 0) return h('span', "汇总");
                        return h('span', (params.index - 1) + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                    }},
                    { key:'belongOrgName',title: '企业名称', fixed: 'left', align: 'center', minWidth:200 },
                    // { key:'rptPeroid',title: '年度', fixed: 'left', align: 'center', minWidth:80 },
                    // { key:'ggEmissions',title: '温室气体排放量(吨)',  align: 'center', minWidth:100 },
                    // { key:'cementProcess',title: '水泥板块产生环境影响的重点工艺流程',  align: 'center', minWidth:145 },
                    { key:'exhaustEmission',title: '废气排放总量（标准立方米）',  align: 'center' , minWidth:130 },
                    { key:'soEmission',title: 'SO2排放量（吨）',  align: 'center' , minWidth:120 },
                    { key:'noxEmission',title: 'NOx排放量（吨）',  align: 'center' , minWidth:120 },
                    { key:'pmEmission',title: '颗粒物排放量（吨）',  align: 'center' , minWidth:120 },
                    { key:'dioxinEmission',title: '二恶英排放量（吨）',  align: 'center' , minWidth:120 },
                    { key:'otherEmission',title: '其他废气（吨）',  align: 'center' , minWidth:120 },
                    { key:'wasterWaterEmission',title: '废水排放总量（吨）',  align: 'center' , minWidth:120 },
                    { key:'codEmission',title: 'COD排放量（吨）',  align: 'center' , minWidth:120},
                    { key:'hmiMission',title: '重金属离子排放量（吨）',  align: 'center' , minWidth:135},
					{ key:'hazardousWasteEmissions',title: '危险废弃物排放总量（吨）',  align: 'center' , minWidth:150},
					{ key:'hazardousWasteDensity',title: '危险废弃物产生密度（吨/万元）',  align: 'center' , minWidth:150},
					{ key:'hazardousWasteDisposalRate',title: '危险废弃物处置率（%）',  align: 'center' , minWidth:150},
                    { key:'oilTreatmentAmount',title: '废弃机油处理量（吨）',  align: 'center' , minWidth:150},
                    { key:'paintTreatmentAmount',title: '废弃油漆处理量（吨）',  align: 'center', minWidth:150 },
                    { key:'otherTreatmentAmount',title: '其他包含在《国家危险废物名录》中的其他危险废物产生及处理量（吨）',  align: 'center', minWidth:230},
                    { key:'harmlessWasteEmissions',title: '无害废弃物排放总量（吨）',  align: 'center' , minWidth:150},
                    { key:'harmlessWasteDensity',title: '无害废弃物密度（吨/万元）',  align: 'center' , minWidth:150},
					{ key:'rockTreatmentAmount',title: '矿山废石处理量（吨）',  align: 'center', minWidth:150 },
                    { key:'tailingsTreatmentAmount',title: '尾矿产生及处理量（吨）',  align: 'center', minWidth:150 },
                    { key:'cementAmount',title: '水泥窑协同处置年处理量（吨）',  align: 'center' , minWidth:150},
                    { key:'otherWasterAmount',title: '其他废弃物产生量（吨）',  align: 'center' , minWidth:150},
                    { key:'isoAmount',title: 'ISO 14001体系认证通过数量（个）',  align: 'center', minWidth:160 },
                    // { key:'envBenefits',title: '环保减排项目及环保效益',  align: 'center' , minWidth:120},
                    { key:'rdInvestment',title: '环保减排项目研发投入（元）',  align: 'center', minWidth:125 },
                    { key:'soReduceAmount',title: 'SO2排放减少量/年（吨）',  align: 'center', minWidth:145 },
                    { key:'noxReduceAmount',title: 'NOX排放减少量/年（吨）',  align: 'center', minWidth:145 },
                    { key:'pmReduceAmount',title: '颗粒物排放减少量/年（吨）',  align: 'center', minWidth:150 },
                    { key:'waterReduceAmount',title: '废水减排总量/年（吨）',  align: 'center', minWidth:145 },
                    { key:'codReduceAmount',title: 'COD排放减少量/年（吨）',  align: 'center', minWidth:145 },
                    // { key:'epRelatedAwards',title: '环保相关奖项',  align: 'center', minWidth:120 },
                    // { key:'relatedProjects',title: '与科研机构合作环保相关项目',  align: 'center', minWidth: 130 },
                    // { key:'createUserName',title: '填表人',  align: 'center', width: 140  },
                    // { key:'creatorPhone',title: '联系电话',  align: 'center', width: 140  },
                    // { key:'createDate',title: '填表时间',  align: 'center', width: 120, render: this.renderCellDate },
                ],
                ruleCustom : {
                    companyId: [ { required: true, message: '请填写企业名称', trigger: 'change' } ],
                    rptPeroidDate:[ { required: true, message: '请填写', trigger: 'change', type:'date' } ],
                },
                tableHeight:10,
                dictMap: {},
                // 弹出框
                orgFieldOptions, // 各集团填报字段配置

                // api
                queryUrl:Api.statisticsEnRptAnnual,
                deleteUrl:Api.deleteEnRptAnnual,
                exportUrl:Api.exportEnRptAnnual,
                bthDeleteUrl:Api.batchDeleteEnRptAnnual,
                getUrl:Api.getEnRptAnnual,
                updateUrl:Api.updateEnRptAnnual,
                saveUrl:Api.saveEnRptAnnual,
            }
        },
        computed:{
            curOrgFieldOptions(){
                var resObj = this.orgFieldOptions[String(this.dataToView.belongOrgId)]
                if (!resObj){
                    resObj = {}
                }
                return resObj
            },
        },
        async mounted() {
            this.setTableHeight();
            // this.dataToQuery.yearDate = new Date()
            this.query();
        },
        methods:{
            ...pageCommonFunction,
            downloadDescriptionExcel(){
                window.open('年报填报说明.xls','_blank')
            },
            rowClassName(row, index) {
                if (index === 0) {
                    return 'table-summary-row';
                }
            },
            deleteData(params) {
                this.deleteDateAjax(params);
            },
            query() {
                if(this.dataToQuery.projectCateArrays) {
                    this.dataToQuery.projectCategories = this.arrayToInFormat(this.dataToQuery.projectCateArrays)
                }
                if(this.dataToQuery.yearDate) {
                    this.dataToQuery.year = this.dataToQuery.yearDate.getFullYear();
                }
                this.dataToQuery.twoLevelOrgId = this.currentUser.twoLevelOrgId?this.currentUser.twoLevelOrgId:undefined
                this.queryAjax();
            },
            submit(name) {
                if(this.dataToView.rptPeroidDate) {
                    this.dataToView.rptPeroid = this.dataToView.rptPeroidDate.getFullYear();
                }
                // this.dataToView.companyId = this.dataToView.belongOrgId;
                // this.dataToView.companyName = this.dataToView.belongOrgName;
                this.submitAjax(name);
            },
            // 弹出表单
            async beforeEditDialogOpen(data) {
                console.log(data.row)
                data.row.rptPeroidDate = new Date(data.row.rptPeroid + '-01-01');
                // data.row.belongOrgId = data.row.companyId;
                // data.row.belongOrgName = data.row.companyName;
            },
            async afterDataToViewInit() {
                await this.getFiles('cementProcess')
                await this.getFiles('envBenefits')
                await this.getFiles('epRelatedAwards')
                await this.getFiles('relatedProjects')
                // this.dataToView.belongOrgId = this.dataToView.companyId;
                // this.dataToView.belongOrgName = this.dataToView.companyName;
                console.log(this.dataToView.cementProcessFiles);
            },
            isFieldVisible(arr){
                var res = false
                for(var i=0,il=arr.length;i<il;i++){
                    var key = arr[i]
                    if (this.curOrgFieldOptions[key]) {
                        res = true
                        break
                    }
                }
                return res
            },
            createEmptyDataToAdd(){
                return {
                    ggEmissions:'',
                    exhaustEmission:'',
                    soEmission:'',
                    noxEmission:'',
                    pmEmission:'',
                    dioxinEmission:'',
                    otherEmission:'',
                    wasterWaterEmission:'',
                    codEmission:'',
                    hmiMission:'',
                    oilTreatmentAmount:'',
                    paintTreatmentAmount:'',
                    otherTreatmentAmount:'',
                    rockTreatmentAmount:'',
                    tailingsTreatmentAmount:'',
                    cementAmount:'',
                    otherWasterAmount:'',
                    isoAmount:'',
                    rdInvestment:'',
                    soReduceAmount:'',
                    noxReduceAmount:'',
                    pmReduceAmount:'',
                    waterReduceAmount:'',
                    codReduceAmount:'',
                    cementProcess:this.get_uuid(),
                    envBenefits:this.get_uuid(),
                    epRelatedAwards:this.get_uuid(),
                    relatedProjects:this.get_uuid(),
                    cementProcessFiles:[],
                    envBenefitsFiles:[],
                    epRelatedAwardsFiles:[],
                    relatedProjectsFiles:[],
                }
            }
        },
        watch:{
        },

    }
</script>

<style lang='css' scoped>
    /deep/ .ivu-table .table-summary-row {
        border-top: 1px solid #e8eaec;
        background-color: #f8f8f9;
    }

    /deep/ .ivu-table .table-summary-row td {
        border-right: 1px solid #e8eaec;
        background-color: #f8f8f9;
    }

    /deep/ .left-right-indent-row > .ivu-col:nth-child(2n-1){
        /*margin-left: 19px;*/
    }
    /deep/ .left-right-indent-row > .ivu-col:nth-child(2n){
        /*margin-right: 19px;*/
    }
</style>
